package org.gvp.manager.controller;

import lombok.RequiredArgsConstructor;
import org.gvp.common.annotation.Operation;
import org.gvp.common.annotation.Tag;
import org.gvp.common.constant.BaseController;
import org.gvp.common.http.Result;
import org.gvp.manager.pojo.GatewayRouteFactory;
import org.gvp.manager.service.GatewayRouteFactoryService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag("网关路由管理接口")
@RestController
@RequestMapping("/manager/admin/route/factory")
@RequiredArgsConstructor
public class GatewayRouteFactoryController implements BaseController<GatewayRouteFactory> {
    private final GatewayRouteFactoryService routeFactoryService;


    @GetMapping("/list/{routeId:\\d+}")
    @Operation(value = "根据路由id,获取路由工厂信息列表", param = "路由id")
    public Result<List<GatewayRouteFactory>> queryListByRouteId(@PathVariable Integer routeId) {
        return Result.ok(this.routeFactoryService.findListByRouterId(routeId));
    }

    @Operation(value = "修改路由工厂信息", param = "路由工厂信息")
    @PostMapping
    @Override
    public Result<Integer> update(@RequestBody GatewayRouteFactory pojo) {
        return Result.ok(this.routeFactoryService.edit(pojo));
    }

    @Operation(value = "添加路由工厂信息", param = "路由工厂信息")
    @PutMapping
    @Override
    public Result<Integer> add(@RequestBody GatewayRouteFactory pojo) {
        return Result.ok(this.routeFactoryService.save(pojo));
    }
}
